package com.ycz.algorithm.utils.list;

/**
 * @Description
 * @ClassName TestMyList
 * @Author yanchengzhi
 * @date 2024.11.20 22:40
 */
public class TestMyList {

    public static void main(String[] args) {
        MyList myList = new MyList();
        System.out.println("容量：" + myList.capacity() + "，元素个数：" + myList.size());
        // 添加元素
        myList.add(1);
        myList.add(2);
        myList.add(3);
        myList.add(4);
        myList.add(5);
        myList.add(6);
        myList.add(7);
        myList.add(8);
        myList.add(9);
        myList.add(10);
        // 列表转为数组
        commonPrint(myList);
        // 临界值再添加元素，列表容量扩容翻倍
        myList.add(11);
        System.out.println("容量：" + myList.capacity() + "，元素个数：" + myList.size());
        // 中间添加元素，索引为2的位置添加20
        myList.add(2, 20);
        commonPrint(myList);
        // 移除元素
        myList.remove(1);
        myList.remove(1);
        myList.remove(1);
        commonPrint(myList);
        System.out.println("索引8的元素为：" + myList.get(8));
        // 将索引为8的元素替换为100
        myList.set(8, 100);
        commonPrint(myList);
    }

    private static void commonPrint(MyList myList) {
        int[] arrs = myList.toArray();
        for (int i : arrs) {
            System.out.print(i + "\t");
        }
        System.out.println();
        System.out.println("容量：" + myList.capacity() + "，元素个数：" + myList.size());
    }

}
